home *** CD-ROM | disk | FTP | other *** search
- Path: andrew.cmu.edu!cn0v+
- From: Chie B Ng <cn0v+@andrew.cmu.edu>
- Newsgroups: comp.lang.c
- Subject: array passing problem
- Date: Wed, 31 Jan 1996 01:27:16 -0500
- Organization: Fifth yr. senior, Mathematics, Carnegie Mellon, Pittsburgh, PA
- Message-ID: <cl3kj4C00bkWMWlEJH@andrew.cmu.edu>
- NNTP-Posting-Host: po8.andrew.cmu.edu
-
- Hello, sorry to bother you, but I can not see what the problem is with
- this code fragment. When I use gcc -ansi to compile this I receive this
- message: "warning: passing arg 1 of 'average' from incompatible pointer
- type". When I run it, I get a segmentation fault in the average
- procedure. Thanks.
-
-
- /* headers go here.... */
-
- typedef unsigned char pixel;
-
- double average(pixel **a, int rows, int columns)
- {
- int i, j, sum = 0;
-
- /* since char is an int, there is no problem with + */
-
- for (i = 0 ; i < rows ; i++)
- for (j = 0 ; j < columns ; j++)
- sum += a[i][j];
-
- return ((double)sum)/(rows*columns);
- }
-
-
- void main(int argc, char **argv[])
- {
- double avg;
- pixel image[200][100];
-
- /* initialize image with values */
- /* .... */
-
- avg = average(image, 200, 100);
-
- printf("%f", avg);
-
- exit(0);
- }
-
-
-
-
-